package com.rd.student.jiaji.class3.wangyanbo.day0728;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Enumerator1 {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        ArrayList names = new ArrayList();

        try (Scanner sc = new Scanner(new FileReader("all.txt"))) {
            sc.useDelimiter("、");
            while (sc.hasNext()) {
                String str = sc.next();
                names.add(str);
            }
            sc.close();
        }

        System.out.println("请输入想要点名的个数：");
        int n = scanner.nextInt();
        Random random = new Random();
        Writer writer = new FileWriter("random.txt");
        HashSet<String> p = new HashSet<>();
        while (p.size() < n) {
            int index = random.nextInt(names.size());
            p.add((String) names.get(index));
        }
        System.out.println("随机点到的人员名单为：");
        for (String name : p) {
            writer.write(name);
            System.out.print(name + " ");
        }
        writer.close();

    }
}
